var express = require('express');
var router = express.Router();
var baseDao = require('../lib/baseDao.js'); // 数据库操作
var app = express();

/* GET users listing. */
router.post('/ab', function (req, res, next) {
  res.cookie("name", 'admin', { maxAge: 1000 * 60 * 60 * 24, httpOnly: true, signed: true });
  if (req.signedCookies && req.signedCookies.token) {
    let uid = JSON.parse(req.signedCookies.token).uid
    let timeStamp = JSON.parse(req.signedCookies.token).timeStamp
    let restTime = new Date().valueOf() - timeStamp
    if(restTime > 1000 * 60 * 60 * 24){
      res.status(401).send({ message: "登陆超时，请重新登陆" });
    }
  }
  res.json({
    status: 200,
    message: 'success',
    data: {
      aaa: 123
    }
  });

  // 查询实例
  baseDao.query('select * from t_user', [], function (err, result, fields) {
    // console.log('查询结果：');
    // console.log(result);
  });
  //添加实例
  var addSql = 'update t_user set username = ? where id = ?';
  var addSqlParams = ['61231231266', 3];
  baseDao.query(addSql, addSqlParams, function (err, result, fields) {
    // console.log('添加成功')
    // console.log(result)
  })

});

module.exports = router;
